import { createStore } from 'vuex'

type userType = {
    username: string,
    password: string,
    remember: boolean
}
type stateOptions = {
    setVisible: boolean,
    userInfo: userType
}
const state:stateOptions = {
    setVisible: false,
    userInfo: {
        username: '',
        password: '',
        remember: true
    }
}

const getters = {
    userInfo: (state:stateOptions) => state.userInfo,
    setVisible: (state:stateOptions) => state.setVisible
}

const mutations = {
    changeSetVisible(state:stateOptions,{payload}:{payload:any}):void {
        state.setVisible = payload
        console.log(state.setVisible)
    },
    setUserInfo: (state:stateOptions,{username,password,remember}:userType) => {
        state.userInfo.username = username
        state.userInfo.password = password
        state.userInfo.remember = remember
    }
}

const actions = {}

const store = createStore({
    state,
    mutations,
    actions,
    getters
})

export default store